package org.raymond.iworks.study.netty.atguigu.nio;

import lombok.extern.slf4j.Slf4j;

import java.nio.IntBuffer;

@Slf4j
public class BasicBuffer {
    public static void main(String[] args) {
        IntBuffer intBuffer = IntBuffer.allocate(5);
        for(int i=0; i<intBuffer.capacity(); i++){
            intBuffer.put(i*2);
        }
        /**
         *  limit = position;
         *  position = 0;
         *  mark = -1;
         */
        intBuffer.flip();
        while (intBuffer.hasRemaining()){
            log.info("{}", intBuffer.get());
        }
        /**
         * position = 0;
         * limit = capacity;
         * mark = -1;
         */
        intBuffer.clear();
        for(int i=0; i<intBuffer.capacity(); i++){
            intBuffer.put(i*3);
        }
        intBuffer.flip();
        while (intBuffer.hasRemaining()){
            log.info("{}", intBuffer.get());
        }
    }

}
